#pragma once
#include "PDTStatement.h"
#include "PDTVar.h"
#include "PDTExp.h"
#include "PDTCondition.h"

class PDTAssert :  public PDTCondition, public TraverseIfc <PDTAssert, PDTNode> { public:  TRAVERSAL_IFC_IMPL(PDTAssert)

public:
	PDTAssert(PDTCodeGraph & CG, PDTExpBool & exp) :
		PDTCondition(CG, exp, ""){

	}

	NodeTypeEnum getType() {
		return PDTAssert_Em;
	}
	bool isAssert() {
		return true;
	}

	virtual bool eval(PDTCodeGraph &CG)
	{
		getExpression()->eval(CG);
		bool expResult = dynamic_cast<PDTBoolConst*>(getExpression()->nValue)->getValue();
		if (expResult) //Return false: stops the program if the boolean expression is true
		{
			return false;
		}
		return true;
	}

	virtual PDTNode* clone(PDTCodeGraph& CG)
	{
		PDTNode* toReturn;
		PDTExpBool* expClone = (PDTExpBool*)(getExpression()->clone(CG));
		toReturn = new PDTAssert(CG, *expClone);
		return toReturn;
	}

	virtual stringstream & toString(stringstream & ss) const {
		ss << "Assert ( ";
		getExpression()->toString(ss);
		ss << ")";
		return ss;
	}
};
